home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / Snippets / Platforms & Tools / MacApp / AEGestalt 1.0b3 / ULookupCommand.cp < prev    next >
Encoding:
Text File  |  1991-12-11  |  3.3 KB  |  111 lines  |  [TEXT/MPS ]

  1. //    ULookupCommand.cp
  2. //     Copyright © 1991 by Apple Computer, Inc. All rights reserved.
  3. //    Kent Sandvik DTS
  4. //    This file contains all the member functions for TLookupCommand,
  5. //    for instance the PPC browsing handling.
  6.  
  7. #ifndef __LOOKUPCOMMAND__
  8. #include "ULookupCommand.h"
  9. #endif
  10.  
  11. #ifndef __AEDOCUMENT__
  12. #include "UAEDocument.h"
  13. #endif
  14.  
  15. //    METHODS:
  16.  
  17. //    Empty constructor - for avoiding ptabs in global data space
  18. #pragma segment ARes
  19. TLookupCommand::TLookupCommand() {}
  20.  
  21.  
  22. //    Initialize TLookupCommand, used for opening the PPCBrowser window
  23.  
  24. #pragma segment ASelCommand
  25. pascal void TLookupCommand::ILookupCommand(CommandNumber theNum, TAEDocument* theDoc)
  26. {
  27.     fDocument = theDoc;
  28.     this->ICommand(theNum, NULL, kCantUndo, kDoesNotCauseChange, NULL);
  29. }
  30.  
  31.  
  32. //    MyPPCBrowserFilter - filter for the PPC Browser with information
  33. //    about what to look for over the network, i.e. who we can talk with.
  34. //     Thanks to Eric Soldan and his Kibitz application for the tips
  35. //    on how to implement this function.
  36.  
  37. #pragma segment ASelCommand
  38. static pascal Boolean MyPPCBrowserFilter(LocationNamePtr /*theLocation*/, 
  39.                                             PortInfoPtr thePortInfo)
  40. {
  41.     OSType    type;
  42.  
  43.     if (thePortInfo->name.portKindSelector == ppcByString)
  44.     // go through every PPC port, and select the one that has the right signature
  45.     {
  46.         BlockMove(thePortInfo->name.u.portTypeStr + 1, Ptr(&type), sizeof(type));
  47.         // The BlockMove is so that we don't get an address error
  48.         // on a 68000-based machine due to referencing a long at
  49.         // an odd-address.
  50.         if (type == kSignature)
  51.             return TRUE;                    // found node
  52.     }
  53.     return FALSE;                            // did not see any
  54. }
  55.  
  56.  
  57. //    Do a PPC Browser lookup of existing nodes that talk the same protocol,
  58. //    i.e. an open application with the same signature
  59.  
  60. #pragma segment ADoCommand
  61. pascal void TLookupCommand::DoIt()
  62. {
  63.     FailInfo        fi;
  64.     TargetID        theTargetID;
  65.     PortInfoRec        thePortInfo;
  66.     AEAddressDesc    targetAddress;
  67.     CStr255            thePrompt = "Find node you want to examine";
  68.     CStr255            theType = "AEGestalt Nodes";
  69.     CStr255            windowTitle;    
  70.  
  71.     if (fi.Try()) {
  72.         FailOSErr(PPCBrowser(thePrompt, theType,  FALSE, theTargetID.location, 
  73.                                 thePortInfo, MyPPCBrowserFilter, ""));
  74.         fi.Success();
  75.     }
  76.     else {
  77.         fDocument->fOKNode = FALSE;
  78.         if (fi.error == userCanceledErr) return;
  79.         else fi.ReSignal();
  80.     }
  81.  
  82.     // signal in document we found OK node
  83.  
  84.     fDocument->fOKNode = TRUE;
  85.     
  86.     // get the AE Address
  87.     
  88.     theTargetID.name = thePortInfo.name;
  89.     FailOSErr(AECreateDesc(typeTargetID, Ptr(&theTargetID), sizeof(theTargetID),
  90.                            targetAddress));
  91.     fDocument->fAEGestaltAddress = targetAddress;
  92.     
  93.     // fix window title, so it will have the title of the port name
  94.     
  95.     switch(theTargetID.location.locationKindSelector){
  96.         case ppcNoLocation:                        // my own machine
  97.             fDocument->SetTitle(CStr255("This local system"));
  98.             break;
  99.         case ppcNBPLocation:                    // we are handling this case
  100.             BlockMove(&theTargetID.location.u.nbpEntity.objStr,&windowTitle,33);
  101.             fDocument->SetTitle(windowTitle);
  102.             break;
  103.         case ppcNBPTypeLocation:                // not handling it yet
  104.             break;
  105.     }
  106. //    Words of wisdom, the nbpEntity record is trash if the PPC selection is on the same
  107. //    local node. It is very important to check the locationKindSelector (as above) and
  108. //    only use the npbEntity record when we have a ppcNBPLocation!!! See IM VI-7 for more
  109. //    information about this (it's well hidden!)
  110. }
  111.